package com.umakr.demo.controller;

import com.umakr.demo.model.Student;
import com.umakr.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by yangliu on 2017/8/16.
 */
@Controller
@RequestMapping("/StudentController")
public class StudentController {
    @Autowired
    StudentService studentService;



//    访问学生表
    @RequestMapping("/showStudent")
    public String showStudent(){
        return "StudentManage/student";
    }

    @RequestMapping("/studentData")
    @ResponseBody
    public List studentData(){
        List<Student> list = studentService.showStudent();
        return list;
    }

//   保存学生表
    @RequestMapping("/saveStudent")
    @ResponseBody
    public List saveStudent(Long sid,String sname,String ssex,Long bid){
        Student student = new Student(sid,sname, ssex, bid);
        studentService.addStudent(student);
        List<Student> list = studentService.showStudent();
        return list;
    }

//    修改学生表
    @RequestMapping("/updataStudent")
    @ResponseBody
    public List updataStudent(Long sid,String sname,String ssex,Long bid){
        Student student = new Student(sid,sname, ssex, bid);
        studentService.updataStudent(student);
        List<Student> list = studentService.showStudent();
        return  list;
    }

//        删除学生
    @RequestMapping("/deleteStudent")
    @ResponseBody
    public List deleteStudent(Long sid,String sname,String ssex,Long bid){
        Student student = new Student(sid,sname, ssex, bid);
        studentService.deleteStudent(student);
        List<Student> list = studentService.showStudent();
        return list;
    }

}

